import { GoodsCommentPictures } from './goodsCommentPicture';
let _GoodsCommentPictures = GoodsCommentPictures;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import GoodsCommentPictureMock from './mallm/goods/goodsCommentPictureMock';
 * GoodsCommentPictureMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mallm/goods/goodsCommentPicture/listKey').reply(config => {
      let params = config.params;
      let mockGoodsCommentPictures = _GoodsCommentPictures.filter(goodsCommentPicture => {
      	if(params.id||params.id==''){ if( goodsCommentPicture.id.indexOf(params.id)>=0) return true;}
      	if(params.commentId||params.commentId==''){ if( goodsCommentPicture.commentId.indexOf(params.commentId)>=0) return true;}
      	if(params.picUrl||params.picUrl==''){ if( goodsCommentPicture.picUrl.indexOf(params.picUrl)>=0) return true;}
      	if(params.sortOrder||params.sortOrder==''){ if( goodsCommentPicture.sortOrder.indexOf(params.sortOrder)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockGoodsCommentPictures
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mallm/goods/goodsCommentPicture/list').reply(config => {
      let params = config.params;
      let mockGoodsCommentPictures = _GoodsCommentPictures.filter(goodsCommentPicture => {
      	var isTrue=false;
      	if(params.id||params.id==''){if(goodsCommentPicture.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.commentId||params.commentId==''){if(goodsCommentPicture.commentId.indexOf(params.commentId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.picUrl||params.picUrl==''){if(goodsCommentPicture.picUrl.indexOf(params.picUrl)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.sortOrder||params.sortOrder==''){if(goodsCommentPicture.sortOrder.indexOf(params.sortOrder)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockGoodsCommentPictures
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockGoodsCommentPictures.length;
      mockGoodsCommentPictures = mockGoodsCommentPictures.filter((goodsCommentPicture, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockGoodsCommentPictures,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mallm/goods/goodsCommentPicture/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _GoodsCommentPictures = _GoodsCommentPictures.filter(goodsCommentPicture => goodsCommentPicture.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mallm/goods/goodsCommentPicture/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _GoodsCommentPictures = _GoodsCommentPictures.filter(goodsCommentPicture => !params.includes(goodsCommentPicture.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mallm/goods/goodsCommentPicture/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { id,commentId,picUrl,sortOrder } = params;
      _GoodsCommentPictures.some(goodsCommentPicture => {
        if (goodsCommentPicture.id === id) {
			goodsCommentPicture.id = id;
			goodsCommentPicture.commentId = commentId;
			goodsCommentPicture.picUrl = picUrl;
			goodsCommentPicture.sortOrder = sortOrder
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mallm/goods/goodsCommentPicture/add').reply(config => {
      var params = JSON.parse( config.data );
      let { id,commentId,picUrl,sortOrder } = params;
      _GoodsCommentPictures.push({
		id:id,
		commentId:commentId,
		picUrl:picUrl,
		sortOrder:sortOrder
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};